<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Feedback extends Model
{
    protected $table = 'c_feedback';

    /****
     * @param $filter
     * 添加意见反馈
     */
    public function addFeedBack($filter)
    {
        $obj = new Feedback();
        if($filter['type'] ==1){
            $info = $obj->getInfos($filter);
            if (!empty($info)) {
                return "您已经反馈过,不能再次反馈!";
            }
        }
        $obj->doctor_id = isset($filter['doctor_id'])?$filter['doctor_id']:"";
        $obj->user_id = $filter['user_id'];
        $obj->type = $filter['type'];
        $obj->back_content = $filter['back_content'];
        $obj->phone = isset($filter['phone'])?$filter['phone']:"";
        return $obj->save();
    }

    public function getInfos($param)
    {
        return $this->where([['user_id','=',$param['user_id']],['doctor_id','=',$param['doctor_id']]])->first();
    }
}
